import refundApi from 'api/refund'

// state
let state = {
  list: {},
  detail: {},
  statusList: [
    {value: '1', label: '待处理'},
    {value: '2', label: '已拒绝'},
    {value: '3', label: '退款中'},
    {value: '4', label: '退款成功'},
    {value: '5', label: '退款失败'}
  ],
  statusMap: {}
}
state.statusList.forEach(item => {
  state.statusMap[item.value] = item.label
})

// actions
const actions = {
  list ({ commit, state }, params) { // 获取退款列表
    refundApi.list(params).then((json) => {
      commit('LIST', {
        params: params,
        data: json.data
      })
    })
  },
  detail ({ commit, state }, params) { // 获取退款详情
    refundApi.detail(params).then((json) => {
      commit('DETAIL', {
        params: params,
        data: json.data
      })
    })
  }
}
// mutations
const mutations = {
  LIST (state, { data }) {
    state.list = data
  },
  DETAIL (state, {data}) {
    state.detail = data
  }
}

export default {
  namespaced: true,
  state,
  actions,
  mutations
}
